package com.mondo.financialwallet.presentation.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.example.common.ui.BaseActivity;
import com.mondo.financialwallet.R;
import com.mondo.financialwallet.presentation.model.FinancialOrderList;
import com.mondo.financialwallet.presentation.ui.adapter.TradingTimelineAdapter;
import com.mondo.financialwallet.presentation.utils.ActivityTitleBarHelper;
import com.mondo.financialwallet.presentation.utils.DateUtils;
import com.mondo.financialwallet.presentation.ui.widget.TimelineItemDecoration;

import java.sql.Timestamp;

import butterknife.Bind;


/**
 * 产品交易状态
 */
public class ProductTradingStatusActivity extends BaseActivity {

    private static final String EXTRA_ORDER_DETAILS = "ORDER_DETAILS";

    public static void launch(Context context, FinancialOrderList order) {
        context.startActivity(
                new Intent(context, ProductTradingStatusActivity.class)
                        .putExtra(EXTRA_ORDER_DETAILS, order)
        );
    }

    @Bind(R.id.trading_timeline_list) RecyclerView mTradingTimelineList;
    @Bind(R.id.name_text_view) TextView mNameTextView;
    @Bind(R.id.transaction_direction_text) TextView mTransactionDirectionText;
    @Bind(R.id.trans_time_text) TextView mTransTimeText;
    @Bind(R.id.payment_text) TextView mPaymentText;
    @Bind(R.id.amount_text_view) TextView mAmountTextView;
    @Bind(R.id.status_text_view) TextView mStatusTextView;
    @Bind(R.id.order_number_text_view) TextView mOrderNumberTextView;

    @Override
    protected int getLayoutID() {
        return R.layout.activity_product_trading_status;
    }

    @Override
    protected void initActions() {
        ActivityTitleBarHelper.init(this, R.string.title_trading_states);

        // 订单列表
        FinancialOrderList order = (FinancialOrderList) getIntent()
                .getSerializableExtra(EXTRA_ORDER_DETAILS);

        mTradingTimelineList.addItemDecoration(new TimelineItemDecoration());
        mTradingTimelineList.setAdapter(TradingTimelineAdapter.create(
                order.getType(),
                order.getDate(),
                DateUtils.timestampToTime(
                        DateUtils.designationDayTimestamp(
                                Timestamp.valueOf(order.getDate()).getTime(),1)
                )));

        // 产品信息
        mOrderNumberTextView.setText(order.getOrderNumber());
        mAmountTextView.setText(order.getAmount());
        mStatusTextView.setText(order.getTypeString());
        mNameTextView.setText(order.getName());
        mTransactionDirectionText.setText(order.getType() == 6
                ? R.string.text_liquidation : R.string.text_buy);
        mTransTimeText.setText(order.getDate());
        mPaymentText.setText(R.string.text_cloud_assets);
    }
}
